package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder

/**
 * @author kuki
 * @date 2022-07-21
 */

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
@JsonTypeName("ProvinceDTO")
data class ProvinceDTO (
    // 序号
    var id: Int? = null,

    // 省份名称
    var name: String? = null,
    var nameChs: String? = null,
    var nameEn: String? = null,

    // 省份代码
    var provinceCode: Long? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): ProvinceDTO? {
            val obj=JacksonUtil.parseObject(json, ProvinceDTO::class.java)!!
            return when(obj){
                is ProvinceDTO -> obj
                else -> null
            }
        }
    }

    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: ProvinceDTO?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}